var projectList = {
	get : function() {
		$.ajax({
			dataType : "json",
			type : "post",
			async : false,
			url : "/app/project!listProjectCategory",
			success : function(data) {
				backUrl.addCookie(data.state);
				if ('success' == data.state) {
					projectList.content(data.msg);
				} else if (data.state == "error") {
					errorAlert(data.msg);
				}
			}
		});
	},
	content : function(data) {
		var dc = $("#dataContent");
		dc.empty();
		var content = "";
		if (data != null && data.length != 0) {
			$("#pageShow").show();
			content = "<tr id='titleTr'><th width='20%' scope='col'><a href='javascript:void()' id='allCheckbox' onclick='checkBoxFunction()'>全选</a></th><th width='80%' scope='col'>项目名称</th></tr>";
			for ( var int = 0; int < data.length; int++) {
				var v = data[int];
				var id = v.id;
				var name = v.name;

				content += "<tr><td align='center'><input name='checkboxProject' type='checkbox' value='" + id
						+ "'/></td><td align='center'><a href='/app/project!getProjectDetailedById?p_id=" + id
						+ "' target='_blank'>" + name + "</a></td></tr>";
			}
		} else {
			content = "<tr id='noData'><td align='center'><h1>暂无数据</h1></td></tr>";
		}
		dc.html(content);
	}
};
/**
 * 全选、全不选
 */
var checkBoxFunctionBoolean = true;
function checkBoxFunction() {
	if (checkBoxFunctionBoolean == true) {
		$("input[name='checkboxProject']").prop("checked", true);
		$("#allCheckbox").text("取消");
		$("#allCheckbox2").text("取消");
	} else {
		$("input[name='checkboxProject']").prop('checked', false);
		$("#allCheckbox").text("全选");
		$("#allCheckbox2").text("全选");
	}
	checkBoxFunctionBoolean = !checkBoxFunctionBoolean;
}
/**
 * 将多选框值组装成字符串并用逗号隔开
 * 
 * @returns {String}
 */
function checkBoxValue(name) {
	var checkedObj = $("input:checkbox[name=" + name + "]:checked");
	var thisValues = "";
	if (null != checkedObj && 0 < checkedObj.length) {
		checkedObj.each(function() {
			thisValues += this.value + ",";
		});
		thisValues = thisValues.substring(0, thisValues.length - 1);
	}
	return thisValues;
}
function updateMoreCategory() {
	var pids = checkBoxValue('checkboxProject');
	var f_id = $("#fcCategoryId").attr("fcCategoryId");
	var s_id = $("#scCategoryId").attr("scCategoryId");
	var t_id = $("#tcCategoryId").attr("tcCategoryId");
	if (typeof (pids) == "undefined" || null == pids || "" == pids || 0 == pids.length) {
		errorAlert("请选择项目！");
	} else if (null == f_id || "" == f_id || 0 == f_id.length || null == s_id || "" == s_id || 0 == s_id.length) {
		errorAlert("请选择类别！");
	} else {
		art.dialog.confirm('确认修改？', function() {
			alert(pids + "  |  " + f_id + "  |  " + s_id + "  |  " + t_id);
			$.ajax({
				dataType : "json",
				type : "post",
				data : {
					"pids" : pids,
					"f_id" : f_id,
					"s_id" : s_id,
					"t_id" : t_id
				},
				async : false,
				url : "/app/project!updateMoreCategory",
				success : function(data) {
					backUrl.addCookie(data.state);
					if ('success' == data.state) {
						projectList.get();
						tipsAlert("处理完成");
					} else if (data.state == "error") {
						errorAlert(data.msg);
					}
				}
			});
		});
	}
}